package 力扣.位运算;

public class 数字的补数476 {
    public static void main(String[] args) {
        int complement = findComplement(2147483647);
        String s = Integer.toBinaryString(2147483647);//1111111111111111111111111111111
        System.out.println(complement);

    }
    public static int findComplement(int num) {
        int re = 0;
        int i = 0;
        while ( i <= 32){
            int pow = (int) Math.pow(2, i);
            if (pow <= num){
                int te = (num & pow) == 0 ? 1 : 0;//num * pow 取出每一位 比特位
                if (te == 1){
                    re |= pow;//使用或运算加上去
                }
                i++;
            }else
                return re;
        }
        return re;
    }
}
